//
//  TourismFlowViewModel.swift
//  AirTravel
//
//  Created by apple on 2021/7/28.
//

import UIKit

protocol TourismFlowDelegate:NSObjectProtocol {
    func tourismFlowClick(data:NSDictionary)
}

class TourismFlowViewModel: NSObject {
    
    var collView : UICollectionView?
    weak var delegate: TourismFlowDelegate?
    let identifyR = "RecommendationColl"
    
    
    func bindViewToViewModel(collView : UICollectionView) {
        self.collView = collView
        self.collView?.dataSource = self
        self.collView?.delegate = self
//        self.collView?.backgroundColor = UIColor.groupTableViewBackground
        let layout = WSLWaterFlowLayout.init()
        layout.delegate = self
        layout.flowLayoutStyle = WSLWaterFlowVerticalEqualWidth

        self.collView?.isScrollEnabled = false
        self.collView?.collectionViewLayout = layout
        self.collView?.showsVerticalScrollIndicator = true
        
        self.collView?.register(UINib.init(nibName: "RecommendationColl", bundle: nil), forCellWithReuseIdentifier: identifyR)
    }
}

extension TourismFlowViewModel:UICollectionViewDataSource,UICollectionViewDelegate{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 10
    }
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifyR, for: indexPath)
        return cell
    }
    
    
}

extension TourismFlowViewModel:WSLWaterFlowLayoutDelegate{
    func waterFlowLayout(_ waterFlowLayout: WSLWaterFlowLayout!, sizeForItemAt indexPath: IndexPath!) -> CGSize {
        let i = indexPath.row % 3
        if i == 0 {
            return CGSize.init(width: (SCREEN_WIDTH - 40)/2, height: 266)
        }else if i == 1{
            return CGSize.init(width: (SCREEN_WIDTH - 40)/2, height: 149 + 96)
        }else{
            return CGSize.init(width: (SCREEN_WIDTH - 40)/2, height: 179 + 96)
        }
    }
    /** 列数*/
    func columnCount(in waterFlowLayout: WSLWaterFlowLayout!) -> CGFloat {
        return 2
    }
    /** 列间距*/
    func columnMargin(in waterFlowLayout: WSLWaterFlowLayout!) -> CGFloat {
        return 10
    }
    /** 行间距*/
    func rowMargin(in waterFlowLayout: WSLWaterFlowLayout!) -> CGFloat {
        return 10
    }
    /** 边缘之间的间距*/
    func edgeInset(in waterFlowLayout: WSLWaterFlowLayout!) -> UIEdgeInsets {
        return UIEdgeInsets(top: 15, left: 15, bottom: 15, right: 15);
    }
}
